package com.item.Service.ImpI;

import com.item.Dao.CustomerDao;
import com.item.POJO.Customer;
import com.item.Service.CustomerService;
import com.item.common.utils.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("customerService")
public class CustomerServiceImpI implements CustomerService {
    @Autowired
    private CustomerDao customerDao;
    @Override
    public Page<Customer> selectCustomerList(Integer page, Integer rows, String custName, String custSource, String custIndustry, String custLevel) {
       Customer customer = new Customer();
       if (StringUtils.isNotBlank(custName)){
           customer.setCust_name(custName);
       }
        if (StringUtils.isNotBlank(custSource)){
            customer.setCust_source(custSource);
        }
        if (StringUtils.isNotBlank(custIndustry)){
            customer.setCust_industry(custIndustry);
        }
        if (StringUtils.isNotBlank(custLevel)){
            customer.setCust_level(custLevel);
        }
        //当前页
        customer.setStart((page-1) * rows);
        //每一页
        customer.setRows(rows);
        //查询客户列表
        List<Customer> customers = customerDao.selectCustomerList(customer);
        //查询客户总数
        Integer count = customerDao.selectCustomerListCount(customer);
        //返回对象
        Page<Customer> result = new Page<>();
        result.setPage(page);
        result.setRows(customers);
        result.setSize(rows);
        result.setTotal(count);
        result.setTotal(count);
        return result;
    }

    @Override
    public int createCustomer(Customer customer) {
        return customerDao.createCustomer(customer);
    }

    @Override
    public Customer getCustomerById(Integer id) {
        return customerDao.getCustomerById(id);
    }

    @Override
    public int customerUpdate(Customer customer) {
        return customerDao.updateCustomer(customer);
    }

    @Override
    public int deleteCustomer(Integer id) {
        return customerDao.deleteCustomer(id);
    }
}
